﻿namespace FSharpMVC

open System
open System.Web.Mvc
open System.Web.Routing
open Castle.Core
open Castle.MicroKernel.Registration
open Castle.Windsor
open RouteCollectionExtensions

type MvcConstraint = { controller:string; action:string; id:string } 
        
type MvcApplication() = 
    inherit System.Web.HttpApplication()    
        
    member x.RegisterRoutes (routes: RouteCollection) = 
        routes.Add (LambdaRoute("/pepepe.aspx", fun c -> Some (RedirectResult "/")))
        routes.MapRoute("Default", // Route name
                    "{controller}/{action}/{id}", // URL with parameters            
                    {controller = "Home"; action = "Index"; id = ""} // Parameter defaults
                    ) |> ignore
        ()
        
    member x.Application_Start() = 
        let container = new WindsorContainer()
        
        ControllerBuilder.Current.SetControllerFactory (LambdaControllerFactory())
            
        x.RegisterRoutes RouteTable.Routes
    